package com.zhxy.config;

import com.zhxy.interceptor.JWTInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private JWTInterceptor jwtInterceptor;
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") //请求url,所有的请求
                .allowedOrigins("*") //跨域的域名，所有的域名都可以
                .allowedMethods("PUT", "DELETE","GET","POST","OPTIONS")
                .allowedHeaders("*")
                .exposedHeaders(HttpHeaders.SET_COOKIE) //允许响应时带上cookie
                .allowCredentials(true).maxAge(3600);

    }

  //  @Override
   // public void addInterceptors(InterceptorRegistry registry) {
      //  registry.addInterceptor(jwtInterceptor)  //配置拦截器
             //   .addPathPatterns("/**")
              //  .excludePathPatterns("/admin/login","/swagger*/**","/webjars/**","/v2/**","/swagger-resources/**","/doc*/**");

  //  }


}
